import Vue from "vue";
import VueRouter from "vue-router";
import store from "../store";
Vue.use(VueRouter);

const router = new VueRouter({
    routes: [{
            path: "/",
            redirect: "/login"
        },

        {
            path: "/login",
            name: "login",
            component: () =>
                import ( /* webpackChunkName: "basepage" */ "@/pages/login/index")
        },
        {
            path: "/yunzhi",
            component: () =>
                import ("@/pages/modules/index"),
            redirect: "/dataIntegration",
            name: "数据集管理",
            meta: { title: "数据集管理", icon: "gwb" },
            children: [{
                    path: "/dataIntegration",
                    name: "数据源管理",
                    component: () =>
                        import ("@/pages/modules/yunzhi/dataIntegration/index"),
                    meta: { title: "数据源管理", icon: "host" }
                },
                {
                    path: "/jobMonitoring",
                    name: "任务监控",
                    component: () =>
                        import ("@/pages/modules/yunzhi/jobMonitoring/index"),
                    meta: { title: "任务监控", icon: "host" }
                },
                {
                    path: "/sql",
                    name: "临时操作",
                    component: () =>
                        import ("@/pages/modules/yunzhi/sql/index"),
                    meta: { title: "临时操作", icon: "host" }
                },
                {
                    path: "/dataSynchronization",
                    name: "数据同步",
                    component: () =>
                        import ("@/pages/modules/yunzhi/dataSynchronization/index"),
                    meta: { title: "数据同步", icon: "host" }
                }
            ]
        },
        {
            // 模块不存在
            path: "/404",
            component: () =>
                import ("@/pages/404/404")
        },
        { path: "*", redirect: "/404", hidden: true }
    ]
});
// 导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
router.beforeEach((to, from, next) => {
    next();
    // let userInfo = sessionStorage.getItem("userInfo");
    // let token = sessionStorage.getItem("token");
    // if (to.matched.some(record => record.meta.requiresAuth)) {
    //   // 判断该路由是否需要登录权限
    //   if (userInfo && token) {
    //     // 登录token
    //     next();
    //   } else {
    //     next({
    //       path: "/"
    //     });
    //     sessionStorage.removeItem("userInfo");
    //     sessionStorage.removeItem("token");
    //   }
    // } else {
    //   // 不要登录权限
    //   if (to.name === "Login" && userInfo && token) {
    //     // 一个浏览器仅允许一个账户登录
    //     next({
    //       path: "/home"
    //     });
    //   } else {
    //     next();
    //   }
    // }
});

router.afterEach((to, from) => {
    if (to.meta.title) {
        document.title = to.meta.title;
    } else {
        document.title = "";
    }
});

export default router;